package com.gorkr.test.component;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author gorkr
 * @date 2022/04/07 22:18
 **/

@Component
public class EsClient {
//    @Value("${elasticsearch.rest.hosts}")
//    private String hosts;
//
//    @Bean
//    public RestHighLevelClient initSimpleClient(){
//
//        HttpHost[] httpHosts = Arrays.stream(hosts.split(",")).map(
//                host ->{
//                    String[] hostParts = host.split(":");
//                    String hostName = hostParts[0];
//                    int port = Integer.parseInt(hostParts[1]);
//                    return new HttpHost(hostName,port,HttpHost.DEFAULT_SCHEME_NAME);
//                }
//        ).filter(Objects::nonNull).toArray(HttpHost[]::new);
//        // :: 是函数式接口 ？
//        return new RestHighLevelClient(RestClient.builder(httpHosts));
//    }
}
    